import type { IPage } from '@/api/interface'
import type { ISysDept } from '@/api/interface/system/admin/dept'
import { ADMIN_MODULE } from '@/api/helper/prefix'
import { http } from '@/utils/http'

/**
 * 查询列表
 * @param params
 * @returns {*}
 */
export function getSysDeptListApi(params: ISysDept.Query) {
  return http.get<IPage<ISysDept.Row>>(`${ADMIN_MODULE}/sys-dept`, params)
}

/**
 * 添加
 * @param params
 * @returns {*}
 */
export function createSysDeptApi(params: ISysDept.Form) {
  return http.post(`${ADMIN_MODULE}/sys-dept`, params)
}

/**
 * 修改
 * @param params
 * @returns {*}
 */
export function updateSysDeptApi(params: ISysDept.Form) {
  return http.put(`${ADMIN_MODULE}/sys-dept`, params)
}

/**
 * 删除
 * @param params
 * @returns {*}
 */
export function removeSysDeptApi(params: { ids: number[] }) {
  return http.delete(`${ADMIN_MODULE}/sys-dept`, params)
}

/**
 * 获取详情
 * @param params
 * @returns {*}
 */
export function getSysDeptDetailApi(params: { id: number }) {
  const { id } = params
  return http.get<ISysDept.Row>(`${ADMIN_MODULE}/sys-dept/${id}`)
}

/**
 * 获取上级菜单树
 * @param params
 * @returns {*}
 */
export function getMenuTree(params: { excludeNodeId?: number; appendRoot?: boolean }) {
  return http.get<ISysDept.Tree[]>(`${ADMIN_MODULE}/sys-dept/tree`, params)
}

/**
 * 获取部门负责人关系
 * @param params
 * @returns {*}
 */
export function getSysDeptLeaderApi() {
  return http.get<ISysDept.LeaderData>(`${ADMIN_MODULE}/sys-dept/leader`)
}

/**
 * 获取部门树
 * @param params
 * @returns {*}
 */
export function getDeptTrees(params: { deptId?: number }) {
  return http.get<ISysDept.Dept>(`${ADMIN_MODULE}/sys-dept/datascope`, params)
}
